package com.bss.model;

// Generated Oct 27, 2011 10:37:49 PM by Hibernate Tools 3.3.0.GA

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import com.andy.basics.AbstractEntity;

@Entity
@Table(name = "Payment")
public class Payment extends AbstractEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8575390243131623144L;

	private int id;

	@NotNull
	private PaymentType paymentType = new PaymentType();

	@NotNull
	private Payable payable;

	private Receipt receipt;

	@NotNull
	@Size(min = 1, max = 50)
	private String remarks;

	@Min(1)
	private Integer amount;

	private Date dateStart = new Date();

	private Date dateEnd = new Date();

	private boolean refund;

	@Id
	@Column(name = "id", unique = true, nullable = false)
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return this.id;
	}

	@Override
	public void setId(final int id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "idPaymentType")
	public PaymentType getPaymentType() {
		return this.paymentType;
	}

	public void setPaymentType(final PaymentType paymentType) {
		this.paymentType = paymentType;
	}

	@Column(name = "remarks", length = 45)
	public String getRemarks() {
		return this.remarks;
	}

	public void setRemarks(final String remarks) {
		this.remarks = remarks;
	}

	@Column(name = "amount")
	public Integer getAmount() {
		return this.amount;
	}

	public void setAmount(final Integer amount) {
		this.amount = amount;
	}

	public void setPayable(final Payable payable) {
		this.payable = payable;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "idPayable")
	public Payable getPayable() {
		return this.payable;
	}

	public void setDateStart(final Date dateStart) {
		this.dateStart = dateStart;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateStart", length = 19)
	public Date getDateStart() {
		return this.dateStart;
	}

	public void setDateEnd(final Date dateEnd) {
		this.dateEnd = dateEnd;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "dateEnd", length = 19)
	public Date getDateEnd() {
		return this.dateEnd;
	}

	public void setRefund(final boolean refund) {
		this.refund = refund;
	}

	public boolean isRefund() {
		return this.refund;
	}

	public void setReceipt(final Receipt receipt) {
		this.receipt = receipt;
	}

	@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
	@JoinColumn(name = "idReceipt")
	public Receipt getReceipt() {
		return this.receipt;
	}

	@Override
	public String toString() {
		return this.paymentType.getName() + "(" + this.amount + ")";
	}

	@Override
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date", length = 19)
	public Date getDate() {
		return this.date;
	}
}
